package com.leiou.stu_login;

import com.leiou.pojo.Student;
import com.leiou.utils.ConnectionDatabaseForSQLSeverUseJdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.function.Consumer;

public class stuLogDaoImpl implements stuLogDao{
    Connection connection=null;
    PreparedStatement pstmt=null;
    ResultSet rset=null;

    public stuLogDaoImpl(){
        connection= ConnectionDatabaseForSQLSeverUseJdbc.getConnection();
    }
    //     学生登录
    @Override
    public Student login(String account, String password) {
        try {
            pstmt=connection.prepareStatement("select username,password from Student where username=? and password=?");
            pstmt.setString(1,account);
            pstmt.setString(2,password);

            System.out.println(account + "" + password);

            rset=pstmt.executeQuery();

            Student student=new Student();
            System.out.println(student);
            if (rset.next()) {

//                student.setStudentId(rset.getInt("studentId"));
                student.setUsername(rset.getString("username"));
                student.setPassword(rset.getString("password"));

                return student;
            }
            System.out.println(student);
            return null;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
